<template>
    <div>
   <h1>居民信息修改</h1>
   <table class="table">
    <thead>
        <tr>
            <td>姓名</td>
            <td>
               <input type="text" v-model="data.name">
            </td>
        </tr>
         <tr>
            <td>类型</td>
            <td>
                 <select v-model="data.userTypeId">
                    <option value="0">请选择</option>
                    <option v-for="b in qwert" :value="b.userTypeId">{{ b.name }}</option>
                 </select>
            </td>
        </tr>
         <tr>
            <td>图像</td>
            <td>
                <input type="file" @change="UpLoad">
                <img :src="'https://localhost:7134'+data.img" style="height: 60px;width: 60px;">
            </td>
        </tr>
         <tr>
            <td>性别</td>
            <td>
                  <input type="radio" name="sex" id="" v-model="data.sex" value="1">男
                   <input type="radio" name="sex" id="" v-model="data.sex" value="2">女
            </td>
        </tr>
         <tr>
            <td>手机号</td>
            <td>
              <input type="text" v-model="data.phone">
            </td>
        </tr>
         <tr>
            <td>房间</td>
            <td>
              <input type="text" v-model="data.room">
            </td>
        </tr>
         <tr>
            <td>楼栋</td>
            <td>
              <input type="text" v-model="data.floor">
            </td>
        </tr>
         <tr>
            <td>状态</td>
            <td>
                   <input type="checkbox" v-model="data.start">选中为未审核，不选为已审核
            </td>
        </tr>
         <tr>
       
            <td colspan="2">
               <input type="button" value="修改" @click="Add">
            </td>
        </tr>
    </thead>
   </table>
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from "vue"
import axios from "axios";
import { useRoute } from "vue-router";
const route=useRoute()
const Fantian=()=>{
    var x=route.query.id
    axios.get("https://localhost:7134/api/User/Fantian",{params:{id:x}}).then(res=>{
        data.value=res.data
    })
}
const data=ref({
    "isDelete": true,
  "createId": 0,
  "createTime": "2025-06-14T01:54:18.591Z",
  "updateId": 0,
  "updateTime": "2025-06-14T01:54:18.591Z",
  "deleteId": 0,
  "deleteTime": "2025-06-14T01:54:18.591Z",
  "id": 0,
  "name": "",
  "userTypeId": 0,
  "img": "",
  "sex": 0,
  "phone": "",
  "room": "",
  "floor": "",
  "start": true
})
onMounted(()=>{
    Xiala()
    Fantian()
})
const qwert=ref([{
     "userTypeId": 0,
    "name": ""
}])
const Xiala=()=>{
  axios.get("https://localhost:7134/api/User/Xiala").then(res=>{
    qwert.value=res.data
  })
}
const Add=()=>{
    if(data.value.name==""){
        alert('姓名不能为空');
        return;
    }
     if(data.value.userTypeId==0){
        alert('类型不能为空');
        return;
    }
     if(data.value.sex==0){
        alert('性别不能为空');
        return;
    }
     if(data.value.phone==""){
        alert('手机号不能为空');
        return;
    }
     if(data.value.room==""){
        alert('房间不能为空');
        return;
    }
     if(data.value.floor==""){
        alert('楼栋不能为空');
        return;
    }

    axios.put("https://localhost:7134/api/User/UptUser",data.value).then(res=>{
        if(res.data>0){
            alert('修改成功');
            location.href='/';
        }
        else{
            alert('修改失败');
        }
    })
}
const UpLoad=(e:any)=>{
     var f=e.target.files[0]
     var fd=new FormData()
     fd.append("file",f)
     axios.post("https://localhost:7134/api/UpLoad/upload",fd).then(res=>{
        data.value.img=res.data
     })
}
</script>

<style scoped>

</style>